package net.doglog;

import java.io.*;

import javax.servlet.*;
import javax.servlet.http.*;

@SuppressWarnings("serial")
public class BlogAdmin extends HttpServlet {
	public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		req.getRequestDispatcher("/admin/index.jsp").forward(req, resp);
	}
	
	public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		String submit = req.getParameter("submit");
		if (submit.equals("Add Page")) {
			String pattern = req.getParameter("pattern");
			String location = req.getParameter("location");
			try {
				PageUtil.newPage(pattern, location);
				req.setAttribute("pagemsg", "page added successfully");
			} catch (Throwable th) {
				req.setAttribute("pattern", pattern);
				req.setAttribute("location", location);
				req.setAttribute("pagemsg", th.getMessage());
			}
		}
		
		req.getRequestDispatcher("/admin/index.jsp").forward(req, resp);
	}
}
